package com.fzg.controller;

import com.fzg.common.enums.ResponseWrapper;
import com.fzg.common.model.param.personal.UpdateCurrentUserNameAndNickNameParam;
import com.fzg.service.impl.PersonalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * create by fzg
 * 2022/6/20 13:54
 */

@RestController
@RequestMapping("/personal")
public class PersonalController {

    @Autowired
    private PersonalService personalService;

    /**
     * 检验token是否过期
     * @return ResponseWrapper
     */
    @PostMapping("/getLoginUserInfoByToken")
    public ResponseWrapper getLoginUserInfoByToken(@RequestParam String token){
        return personalService.getLoginUserInfoByToken(token);
    }

    /**
     * 更新当前用户的头像
     * @return ResponseWrapper
     */
    @PostMapping("/updateUserAvatar")
    public ResponseWrapper updateUserAvatar(HttpServletRequest request, @RequestParam String avatarUrl){
        return personalService.updateUserAvatar(request,avatarUrl);
    }

    /**
     * 更新当前用户的背景
     * @return ResponseWrapper
     */
    @PostMapping("/updateUserBg")
    public ResponseWrapper updateUserBg(HttpServletRequest request, @RequestParam String bgUrl){
        return personalService.updateUserBg(request,bgUrl);
    }

    /**
     * 查询是否有相同的用户名
     * @return ResponseWrapper
     */
    @GetMapping("/isSimpleUserName")
    public ResponseWrapper isSimpleUserName(HttpServletRequest request, @RequestParam String userName){
        return personalService.isSimpleUserName(request,userName);
    }

    /**
     * 更新当前登陆用户的用户名和昵称
     * @return ResponseWrapper
     */
    @PostMapping("/updateCurrentUserNameAndNickName")
    public ResponseWrapper updateCurrentUserNameAndNickName(HttpServletRequest request, @RequestBody UpdateCurrentUserNameAndNickNameParam param){
        return personalService.updateCurrentUserNameAndNickName(request,param);
    }

    /**
     * 获取轮播图的内容
     * @return ResponseWrapper
     */
    @GetMapping("/getSwiperContent")
    public ResponseWrapper getSwiperContent(){
        return personalService.getSwiperContent();
    }

}
